package com.transmit.host;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FileAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<String> name;
	private TextView nameTextView;
	private ImageView icon;
	private int[] drawable;

	public FileAdapter(LayoutInflater inflater, List<String> name, int width,
			int height) {
		super();
		this.inflater = inflater;
		this.name = name;
		initDrawable();
	}

	@Override
	public int getCount() {
		if (name != null)
			return name.size();
		else
			return 0;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if (convertView == null) {
			if (name != null) {
				view = inflater.inflate(R.layout.adapter, null);
			} else
				return null;

		} else {
			view = convertView;
		}
		nameTextView = (TextView) view.findViewById(R.id.nameTextView1);
		icon = (ImageView)view.findViewById(R.id.imageView1);
		int count = (int)(Math.random()*100%12);
		icon.setBackgroundResource(drawable[count]);
		nameTextView.setText(name.get(position));
		return view;
	}

	private void initDrawable(){
		drawable = new int[12];
		drawable[0] = R.drawable.i1;
		drawable[1] = R.drawable.i2;
		drawable[2] = R.drawable.i3;
		drawable[3] = R.drawable.i4;
		drawable[4] = R.drawable.i5;
		drawable[5] = R.drawable.i6;
		drawable[6] = R.drawable.i7;
		drawable[7] = R.drawable.i8;
		drawable[8] = R.drawable.i9;
		drawable[9] = R.drawable.i10;
		drawable[10] = R.drawable.i11;
		drawable[11] = R.drawable.i12;
		
	}
	
}
